<?php

namespace App\Http\Controllers\Admin;

use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Models\Banner;
use Illuminate\Http\Request;

class BannerController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index(Request $request)
    {
        $params = $request->only('title','status');
        $res = Banner::getQueryData($params);
        return apiResponse(data: $res);
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $res = Banner::create($request->all());
        return apiResponse(data: $res);
    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {
        $res = Banner::query()->findOrFail($id);
        return apiResponse(data: $res);
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        $banner = Banner::query()->findOrFail($id);
        $banner->update($request->all());
        return apiResponse(data: $request->all());
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $ids)
    {
        Banner::destroy(explode(',', $ids));
        return apiResponse(data: $ids);
    }
}
